package scantask.server.utilities.logging;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SingletonLogger {

	private static final Logger INSTANCE;
	
	private SingletonLogger() {}
	
	static {
		
		// creating logger called "Sim1BankLog"
		INSTANCE = Logger.getLogger("resource\\server-log.txt");
		
		// The root logger's handlers default to INFO. We have to
	    // crank them up. We could crank up only some of them
	    // if we wanted, but we will turn them all up.
	/*	IF I Want To Print The Log To The Console    */   /*
			Handler[] handlers = Logger.getLogger("").getHandlers();
	    for ( int index = 0; index < handlers.length; index++ ) {
	      handlers[index].setLevel( Level.FINEST );
	    }   */
		
		final Handler[] handlers = Logger.getLogger("").getHandlers();
	    for ( int index = 0; index < handlers.length; index++ ) {
	    	handlers[index].setFormatter(new MyLogFormat());
	    	handlers[index].setLevel( Level.SEVERE );
	    } 
	    
		Handler fh= null;
		
		try{
		fh = new FileHandler("resource\\server-log.txt");
		}catch(IOException e){INSTANCE.severe(e.toString());}
		
		//Change the format of the log file to My Format delete this line if u want a XML Format
		fh.setFormatter(new MyLogFormat());
		
	    //set the fh Hendler level to be the FINEST
		fh.setLevel(Level.FINEST);
		
		//logger output is written to a file in fh handler - logFilePath
		INSTANCE.addHandler(fh);
		INSTANCE.setLevel(Level.FINEST);

	}
	
	public static Logger getLogger() {
		return INSTANCE;
	}
}
